﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using CapturarObjetos.Nucleo;

namespace CapturarObjetos
{
    class HUD
    {

        ClockTimer clock;

        GraphicsDeviceManager graphics;
        public static Texture2D hudIMG;
        private SpriteFont fontCombo;

        Texture2D barraTempoTexture;
        Color[] barraTempoData;
        int tempoCurr, tempoMax;

        public HUD(GraphicsDeviceManager graphics, ContentManager content, ClockTimer clok)
        {
            clock = clok;
            hudIMG = content.Load<Texture2D>("Hud");
            fontCombo = content.Load<SpriteFont>("font1");

            this.graphics = graphics;

            barraTempoTexture = new Texture2D(graphics.GraphicsDevice, 800, 8);
            barraTempoData = new Color[800 * 8];
            for (int i = 0; i < barraTempoData.Length; ++i) barraTempoData[i] = Color.Yellow;
            barraTempoTexture.SetData(barraTempoData);
            tempoMax = 80*60;
            tempoCurr = 60*60;
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(hudIMG, new Rectangle(200, 0, 300, 70), new Rectangle(0, 0, 300, 70), Color.White);

            //spriteBatch.DrawString(Game1.tahoma, "Tempo: "+clock.displayClock, new Vector2(210, 10), Color.Red);
            if ((Game1.Pontos * 20) > Game1.ptAtual)
                Game1.ptAtual += Game1.level + Game1.combo;

            spriteBatch.DrawString(Game1.tahoma, "Pontuação: "+Game1.ptAtual.ToString(), new Vector2(210, 35), Color.White);
            if (Game1.combo > 1)
                spriteBatch.DrawString(fontCombo, "Combo X " + Game1.combo.ToString(), new Vector2(250, 80), Color.Yellow);
            else { }

            spriteBatch.DrawString(Game1.tahoma, "Level: " + Game1.level.ToString(), new Vector2(210, 10), Color.White);

            spriteBatch.DrawString(Game1.tahoma, "Próxima Arma:" + Game1.proxTiro, new Vector2(280, 10), Color.White);

            Texture2D rect = new Texture2D(graphics.GraphicsDevice, 800, 10);

            Color[] data = new Color[800 * 10];
            for (int i = 0; i < data.Length; ++i) data[i] = Color.Black;
            rect.SetData(data);

            spriteBatch.Draw(rect, new Vector2(0, 470), new Rectangle(0, 460, rect.Width, rect.Height), Color.White);
            spriteBatch.Draw(barraTempoTexture, new Vector2(0, 471), new Rectangle(0, barraTempoTexture.Height, (int)(barraTempoTexture.Width * ((double)tempoCurr / tempoMax)), barraTempoTexture.Height), Color.White);
            
          
        }

        public void Update(GameTime gameTime, int tempo)
        {
            if (tempoCurr > tempo * 60)
                tempoCurr--;
            else if (tempoCurr < tempo * 60)
                tempoCurr = tempo*60;
        }
    }
}
